﻿using Estsh.Core.Wms.IServices;
using Estsh.Core.Model.Result;
using Microsoft.AspNetCore.Mvc;
using Estsh.Core.Models;
using Estsh.Core.Controllers;

namespace Estsh.Core.Web.Areas.Wms.Controllers.OutStock
{
    [Route("wms/[controller]")]
    [ApiController]
    public class OutSourceDeliveryController : WmsBaseController
    {
        private IOutSourceDeliveryService service;

        // GET: LoginController
        public OutSourceDeliveryController(IOutSourceDeliveryService _service)
        {
            service = _service;
        }

        [HttpPost("GetOutSourceDeliveryOrderList")]
        public IActionResult GetOutSourceDeliveryOrderList(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetOutSourceDeliveryOrderList(orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("GetOutSourceDeliveryOrderListByOrderNo")]
        public IActionResult GetOutSourceDeliveryOrderListByOrderNo(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.GetOutSourceDeliveryOrderListByOrderNo(orderNo);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }

        [HttpPost("CheckStockByCartonAlocate")]
        public IActionResult CheckStockByCartonAlocate(Newtonsoft.Json.Linq.JObject jobj)
        {
            string cartonNo = jobj["cartonNo"].ToString().Trim();
            string orderNo = jobj["orderNo"].ToString().Trim();
            string isGroup = jobj["isGroup"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();


            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.CheckStockByCartonAlocate(cartonNo, orderNo,isGroup, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
        [HttpPost("SetOutSourceDeliveryOrderNoSubmit")]
        public IActionResult SetOutSourceDeliveryOrderNoSubmit(Newtonsoft.Json.Linq.JObject jobj)
        {
            string orderNo = jobj["orderNo"].ToString().Trim();
            string loginId = jobj["loginId"].ToString().Trim();

            WmsResponseResult result = new WmsResponseResult();
            try
            {
                SetObjectDetail obj = service.SetOutSourceDeliveryOrderNoSubmit(orderNo, loginId);
                result.Success = true;
                result.Data = obj;
            }
            catch (Exception ex)
            {
                result.Msg = ex.Message;
            }
            return Json(result);
        }
        
    }
}
